package com.powernode.spring6.service;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author 动力节点
 * @version 1.0
 * @className SecurityAspect
 * @since 1.0
 **/
@Aspect
@Component
@Order(0) // 数字越小，优先级越高。
public class SecurityAspect { // 安全切面

    /*
    aop的顺序，Order注解的数字越小，优先级越高
    前环绕：安全...
    前置通知：安全...
    前环绕
    前置通知
    目标方法的方法名：destroy
    异常通知
    后置通知(最终通知)
    异常通知：安全...
    后置通知(最终通知)：安全...

     */

    // 通知 + 切点
    //@Before("execution(* com.powernode.spring6.service..*(..))")
    @Before("com.powernode.spring6.service.LogAspect.commonCutPoint()")
    public void beforeAdvice() {
        System.out.println("前置通知：安全...");
    }


    @Around("com.powernode.spring6.service.LogAspect.commonCutPoint()")
    public void around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("前环绕：安全...");
        joinPoint.proceed();
        System.out.println("后环绕：安全....");
    }

    @AfterReturning("com.powernode.spring6.service.LogAspect.commonCutPoint()")
    public void afterReturning() {
        System.out.println("返回通知：安全...");
    }


    @AfterThrowing("com.powernode.spring6.service.LogAspect.commonCutPoint()")
    public void afterThrowing() {
        System.out.println("异常通知：安全...");
    }

    @After("com.powernode.spring6.service.LogAspect.commonCutPoint()")
    public void after() {
        System.out.println("后置通知(最终通知)：安全...");
    }

}
